package com.yujie.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yujie.domain.DictionaryCommon;
import com.yujie.service.DictionaryCommonService;
import com.yujie.util.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (DictionaryCommon)表控制层
 *
 * @author wangyujie
 * @since 2023-08-14 20:33:28
 */
@RestController
@RequestMapping("dictionaryCommon")
public class DictionaryCommonController {

    /**
     * 服务对象
     */
    @Resource
    private DictionaryCommonService dictionaryCommonService;

    /**
     * 分页查询所有数据
     */
    @PostMapping("/list")
    public R page(@RequestParam(value = "size", defaultValue = "10") Integer size, @RequestParam(value = "current", defaultValue = "0") Integer current, DictionaryCommon query) {
        QueryWrapper<DictionaryCommon> queryWrapper = new QueryWrapper<>();
        queryWrapper.setEntity(query);
        Page<DictionaryCommon> page = new Page();
        page.setCurrent(current);
        page.setSize(size);
        return R.ok().setData(this.dictionaryCommonService.page(page, queryWrapper));
    }


    /**
     * 新增数据
     */
    @PostMapping("/insert")
    public R save(@RequestBody DictionaryCommon query) {
        return R.ok().setData(this.dictionaryCommonService.save(query));
    }

    /**
     * 修改数据
     */
    @PostMapping("/update")
    public R updateById(@RequestBody DictionaryCommon query) {
        return R.ok().setData(this.dictionaryCommonService.updateById(query));
    }

    /**
     * 单条/批量删除数据
     */
    @PostMapping("/delete")
    public R delete(@RequestBody List<Long> id) {
        return R.ok().setData(this.dictionaryCommonService.removeByIds(id));
    }
}

